﻿using Xejen.Communication.Configuration;
using Xejen.Communication.Endpoints;
using Xejen.Communication.Http.Configuration;
using System.Threading;
using System.Threading.Tasks;

namespace Xejen.Communication.Http.Communicator
{
    /// <summary>
    /// 提供Http通讯器专用接口
    /// </summary>
    /// <creator>marc</creator>
    public interface IHttpCommunicator : ICommunicator<HttpConfig, HeartbeatConfig>
    {
        /// <summary>
        /// 发送Delete请求
        /// </summary>
        /// <param name="address"><inheritdoc cref="HttpAddress" path="/summary"/></param>
        /// <param name="httpConfig">变更Http配置信息</param>
        /// <param name="timeout">超时时间，单位：毫秒</param>
        /// <param name="cancellationToken">是否取消的令牌</param>
        /// <example>
        /// var response = await _provider.DeleteAsync{ResponseDto{object}}(_server + "/admin/delete?classId=" + classId, null, headers: new NameValueCollection { { "X-Access-Token", _token } });
        /// </example>
        /// <returns></returns>
        Task<HttpResponse> DeleteAsync(HttpAddress address, HttpConfig httpConfig = null, int timeout = -1,  CancellationToken cancellationToken = default);
        /// <summary>
        /// 发送Get请求
        /// </summary>
        /// <param name="httpConfig">变更Http配置信息</param>
        /// <param name="address"><inheritdoc cref="HttpAddress" path="/summary"/></param>
        /// <param name="timeout">超时时间，单位：毫秒</param>
        /// <param name="cancellationToken">是否取消的令牌</param>
        /// <example>
        /// await provider.GetAsync{object}("http://192.168.3.164:9010/api/model-mgt/models");
        /// </example>
        /// <returns></returns>
        Task<HttpResponse> GetAsync(HttpAddress address, HttpConfig httpConfig = null, int timeout = -1, CancellationToken cancellationToken = default);
        /// <summary>
        /// 发送Post请求
        /// </summary>
        /// <param name="httpConfig">变更Http配置信息</param>
        /// <param name="address"><inheritdoc cref="HttpAddress" path="/summary"/></param>
        /// <param name="input">待提交的数据对象，通常是个模型model数据。会被封闭为json传输</param>
        /// <param name="timeout">超时时间，单位：毫秒</param>
        /// <param name="cancellationToken">是否取消的令牌</param>
        /// <example>
        /// await provider.PostAsync{object}("http://192.168.3.164:9010/api/model-mgt/models", new { ownerId = "abc", name = "才能当上" });
        /// 或者
        /// await _provider.PostAsync{ResponseDto{LoginDto}}(
        ///         _server + "admin/sys/login",
        ///         new
        ///         {
        ///             username = userName,
        ///             password = password,
        ///             skipCaptcha = true
        ///         },
        ///         headers: new NameValueCollection
        ///         {
        ///             { "x-company-code", "a234" }
        ///         });
        /// </example>
        /// <returns></returns>
        Task<HttpResponse> PostAsync<TInput>(HttpAddress address, TInput input, HttpConfig httpConfig = null, int timeout = -1, CancellationToken cancellationToken = default);
        /// <summary>
        /// 发送Put请求
        /// </summary>
        /// <param name="address"><inheritdoc cref="HttpAddress" path="/summary"/></param>
        /// <param name="httpConfig">变更Http配置信息</param>
        /// <param name="input">待提交的数据对象。会被封装为json传输</param>
        /// <param name="timeout">超时时间，单位：毫秒</param>
        /// <param name="cancellationToken">是否取消的令牌</param>
        /// <returns></returns>
        Task<HttpResponse> PutAsync<TInput>(HttpAddress address, TInput input, HttpConfig httpConfig = null, int timeout = -1, CancellationToken cancellationToken = default);
    }
}